from django.db import models
from django.contrib.auth.models import User

from model_manager.project_manager_user import PMUDataManager
from model_manager.project_manager_comments import ProjectManagerCommentsManager

from timesheet.models import Project
from timesheet.models import Time


class ProjectManager(models.Model):
    manager = models.OneToOneField(User)
    
    @staticmethod
    def is_manager(user):
        try:
            ProjectManager.objects.get(manager=user)
            is_manager = 1
        except(ProjectManager.DoesNotExist):
            is_manager = 0
            
        return is_manager

    def __unicode__(self):
        return u'%s' % (self.manager)


class ProjectManagerUser(models.Model):
    manager = models.ForeignKey(ProjectManager)
    his_user = models.ForeignKey(User)
    project = models.ForeignKey(Project)
    
    objects = PMUDataManager()
    
    def __unicode__(self):
        return u'%s %s %s' % (self.manager, self.his_user, self.project)
        
class ProjectManagerComments(models.Model):
    manager = models.ForeignKey(ProjectManager)
    time = models.ForeignKey(Time)
    comments = models.TextField()

    objects = ProjectManagerCommentsManager()
    
    def __unicode__(self):
        return u'%s %s' % (self.manager, self.time)
